package com.atguigu.yygh.user.controller.admin;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.acl.User;
import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author mgx
 * @version 1.0
 * @description: TODO
 * @date 2022/9/3 22:02
 */
@Api(tags = {"管理员系统的用户信息管理"})
@RestController
@RequestMapping("/administrator/userinfo")
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @PutMapping("/auth/{id}/{authStatus}")
    public R approval(@PathVariable("id") Long id,
                      @PathVariable("authStatus")Integer authStatus){
        UserInfo userInfo = new UserInfo();
        userInfo.setId(id);
        userInfo.setAuthStatus(authStatus);
        userInfoService.updateById(userInfo);
        return R.ok();
    }


    @GetMapping("/detail/{id}")
    public R detail(@PathVariable("id")Long id) {
        // 需要返回用户和就诊人信息，所以使用map进行传参
        Map<String, Object> map = userInfoService.detail(id);
        return R.ok().data(map);
    }

    @ApiOperation("修改用户状态")
    @PutMapping("/updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id") Long id,
                          @PathVariable("status")Integer status) {
        userInfoService.updateStatus(id, status);
        return R.ok();
    }

    @ApiOperation(value = "用户信息列表分页查询")
    @GetMapping("/{pageNum}/{limit}")
    public R getUserInfoPage(@PathVariable("pageNum")Integer pageNum,
                             @PathVariable("limit")Integer limit,
                             UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> page = userInfoService.getUserInfoPage(pageNum, limit, userInfoQueryVo);
        return R.ok().data("total", page.getTotal()).data("list", page.getRecords());
    }
}
